package cn.doitedu.demo9.groovy_test;

import groovy.lang.GroovyClassLoader;

public class JitCompileLoadTest {

    public static void main(String[] args) throws InstantiationException, IllegalAccessException {

       /* RuleCalculatorX ruleCalculatorX = new RuleCalculatorX();
        ruleCalculatorX.init();
        ruleCalculatorX.calc();*/

        String calculatorCode = "package cn.doitedu.demo9.groovy_test\n" +
                "\n" +
                "class RuleCalculatorX implements RuleCalculator {\n" +
                "\n" +
                "    public void init(){\n" +
                "        System.out.println(\"初始化了\")\n" +
                "    }\n" +
                "\n" +
                "    public void calc(){\n" +
                "        System.out.println(\"运算了\")\n" +
                "    }\n" +
                "\n" +
                "\n" +
                "}";

        // 动态编译加载源代码
        GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
        Class aClass = groovyClassLoader.parseClass(calculatorCode);
        // 反射实例对象
        RuleCalculator ruleCalculatorX = (RuleCalculator) aClass.newInstance();
        ruleCalculatorX.init();
        ruleCalculatorX.calc();


    }

}
